{% extends "base.html" %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h1>管理后台</h1>
    <a href="{{ url_for('new_antique') }}" class="btn btn-primary">添加新藏品</a>
</div>

<div class="table-responsive">
    <table class="table table-striped">
        <thead>
            <tr>
                <th>ID</th>
                <th>名称</th>
                <th>描述</th>
                <th>添加时间</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            {% for antique in antiques %}
            <tr>
                <td>{{ antique.id }}</td>
                <td>{{ antique.name }}</td>
                <td>{{ antique.description[:50] }}{% if antique.description|length > 50 %}...{% endif %}</td>
                <td>{{ antique.created_at.strftime('%Y-%m-%d') }}</td>
                <td>
                    <a href="{{ url_for('antique_detail', id=antique.id) }}" class="btn btn-sm btn-info">查看</a>
                    <a href="{{ url_for('edit_antique', id=antique.id) }}" class="btn btn-sm btn-warning">编辑</a>
                    <button class="btn btn-sm btn-danger" onclick="deleteAntique({{ antique.id }})">删除</button>
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>

<script>
function deleteAntique(id) {
    if (confirm('确定要删除这个藏品吗？')) {
        fetch(`/admin/antique/${id}/delete`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
        }).then(response => {
            if (response.ok) {
                window.location.reload();
            }
        });
    }
}
</script>
{% endblock %} 